import java.util.Comparator;
import java.util.PriorityQueue;

class Person implements Comparable<Person>{
    public String name;
    public int age;
    public Person(String name,int age){
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

// Person要比较，要实现Compare接口，重写compareTo方法
//    大于小于的比较
    @Override
    public int compareTo(Person o) {
        return this.age - o.age;
    }
}
//  比较器
class NameComparator implements Comparator<Person> {
    @Override
    public int compare(Person o1, Person o2) {
//        字符串比较，字符串自己有实现自己的toString方法
        return o1.name.compareTo(o2.name);
    }
}

//对compareto方法的调整就可以实现大根堆或是小根堆
class Imp implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
//        return o2-o1;
    }
}

public class testdemo01 {
    public static void main3(String[] args) {
        Imp imp = new Imp();
//       这样，对compare进行重写，就能从小根堆转变大根堆
        PriorityQueue priorityQueue = new PriorityQueue(imp);
        priorityQueue.offer(10);
        priorityQueue.offer(4);
        System.out.println("=====");
    }

    public static void main2(String[] args) {
        Person person1 = new Person("zhangsan",10);
        Person person2 = new Person("lisi",4);
        PriorityQueue<Person> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(person1);
        priorityQueue.offer(person2);


    }
    public static void main1(String[] args) {
        Person person1 = new Person("zhangsan",10);
        Person person2 = new Person("lisi",4);
        System.out.println(person1.compareTo(person2));

        NameComparator nameComparator = new NameComparator();
        System.out.println(nameComparator.compare(person1,person2));
    }
}
